package com.cts.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cts.entity.Category;
import com.cts.entity.Friend;
import com.cts.model.dto.CategoryDTO;
import com.cts.model.vo.PageResultVO;
import com.cts.service.CategoryService;
import com.cts.mapper.CategoryMapper;
import com.mysql.cj.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author tongshengchen
* @description 针对表【category】的数据库操作Service实现
* @createDate 2023-02-06 12:25:57
*/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements CategoryService{

    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public PageResultVO<Category> getCateGoryList(CategoryDTO categoryDTO) {
        LambdaQueryWrapper<Category> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(!StringUtils.isNullOrEmpty(categoryDTO.getCategoryName()),Category::getCategoryName, categoryDTO.getCategoryName());
        Page<Category> page = new Page<>(categoryDTO.getPageNo(),categoryDTO.getPageSize());
        IPage<Category> pageResult = categoryMapper.selectPage(page, lambdaQueryWrapper);
        return new PageResultVO(pageResult.getTotal(), pageResult.getRecords());
    }
}




